<template>
	<view class="selectidentity">
		<u-navbar leftText="选择身份" title="选择身份" :safeAreaInsetTop="true">
			<view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" size="20" @click="back"></u-icon>
			</view>
		</u-navbar>
	

		<view class="selectbox">
			<view class="selectitem">
				<image v-if="!teacherFlag" class="teacherimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/teacher.png"
					@click="handleteacher"></image>
				<image v-else class="teacherimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/teachered.png"></image>
				<view class="teachertext">
					我是导师
				</view>
			</view>

			<view class="selectitem">
				<image v-if="!studentFlag" class="teacherimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/student.png"
					@click="handlestudent"></image>
				<image v-else class="teacherimg" src="http://sssx.nanjingyunpeng.cn/uploads/tupian/image/studented.png"></image>
				<view class="teachertext">
					我是学生
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		usermessage,
		selectteacherOrstudent
	} from "@/api/api.js"
	export default {
		data() {
			return {
				teacherFlag: false,
				studentFlag: false,
			}
		},
		onLoad() {
			this.getusermessage()
		},
		methods: {
			//获取当前用户信息
			async getusermessage() {
				let res = await usermessage()
				if (res.code == 1) {
					console.log("当前用户信息", res)
					uni.setStorageSync("userInfo", JSON.stringify(res.data))
					if (res.data.is_identity == 1) {
						
							uni.navigateTo({
								url: "/pages/home/index"
							})
						
						
					}
				}
			},
			handleteacher() {
				this.teacherFlag = true
				this.studentFlag = false
				this.selectteacherOrstudents("1")

			},
			handlestudent() {
				this.studentFlag = true
				this.teacherFlag = false
				this.selectteacherOrstudents("2")

			},
			async selectteacherOrstudents(type) {
				let res = await selectteacherOrstudent({
					identity: type
				})
				if (res.code == 1) {
					console.log("选择身份", res)
					if (type == "1") {
						setTimeout(function() {
							uni.navigateTo({
								url: "/pages_teachers/perfect/index"
							})
						}, 200)
					} else {
						setTimeout(function() {
							uni.navigateTo({
								url: "/pages_students/perfect/index"
							})
						}, 200)
					}
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					})
				}

			},
			back() {
				uni.navigateTo({
					url: "/pages/authentication/index"
				})
			}
		},
		onHide() {

		}
	}
</script>

<style scoped lang="scss">
	

	.selectidentity {
		.selectbox {
			width: 240rpx;
			height: 750rpx;
			margin: 0 auto;
			margin-top: 336rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;

			.selectitem {
				display: flex;
				flex-direction: column;
				align-items: center;

				.teacherimg {
					width: 240rpx;
					height: 240rpx;
				}

				.teachertext {
					font-size: 32rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #333333;
					line-height: 38rpx;
					margin-top: 30rpx;
				}
			}
		}
	}
</style>